package svc

import (
	"github.com/zeromicro/go-zero/core/stores/cache"
	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"go-zero-all/apps/user/models"
	"go-zero-all/apps/user/rpc/internal/config"
)

type ServiceContext struct {
	Config    config.Config
	Cache     cache.Cache
	Redis     *redis.Redis
	UserModel models.UserModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	conn := sqlx.NewMysql(c.DataBase.MySQL)
	return &ServiceContext{
		Config:    c,
		Redis:     redis.MustNewRedis(c.GeneralRedis),
		UserModel: models.NewUserModel(conn, c.CacheRedis),
	}
}
